﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core;
using Telerik.Windows.Controls.GridView;
using Telerik.Windows.Controls;
using Baosight.Platform.Core.ServiceModel;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Baosight.Platform.Core.UI.Controls;
using Baosight.ZNH.ZMCD.UI.Block;

namespace Baosight.ZNH.ZMCD.UI
{
    public partial class ZMCD06 : EFViewCmes
    {
        private DocBlock block = new DocBlock();
        /// <summary>
        /// 生产文档
        /// </summary>
        /// Title:ZMCD06,ServiceZMCD02
        /// Copyright:Baosight Software LTD.co Copyright (c) 2011
        /// Company:上海宝信软件股份有限公司
        /// Author: 张志芳
        /// Version: 1.0
        /// History:
        ///       2011-06-19  张志芳   [创建]
        ///
        public ZMCD06()
        {
            InitializeComponent();
        }

        public override void Initialize(Baosight.Platform.Core.EIInfo initData)
        {
            initData.AddBlock(block.GetDocType());
            initData.AddBlock(block.GetBusinessType());
            base.Initialize(initData);
        }

        /// <summary>
        /// 重写查询方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void OnQueryButtonClick(object sender, RoutedEventArgs e)
        {
            this.grid.Refresh();
        }

        /// <summary>
        /// 查看明细
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void More_HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            HyperlinkButton link = sender as HyperlinkButton;
            EIRow row = (link.ParentOfType<GridViewRow>().Item as UIBaseEntity).GetEIRow();
            EIInfo _eIInfo = new EIInfo();
            EIBlock eIBlock = _eIInfo.AddBlock("result");
            eIBlock.SetColumns(this.EIDataContext.GetBlock("result").GetColumns());
            eIBlock.SetRow(0, row);

            _eIInfo.AddBlock(this.EIDataContext.GetBlock("cmes.cd.engineering"));
            _eIInfo.AddBlock(block.GetBusinessType());
            _eIInfo.AddBlock(block.GetDocType());
            ZMCD04 zmcd04 = new ZMCD04();
            zmcd04.EIDataContext = new Platform.Core.UI.EIDataContext();
            zmcd04.EIDataContext.Update(_eIInfo);
            zmcd04.eTitle = "生产文档—明细";
            zmcd04.Loaded += new RoutedEventHandler(ZMCD04_Loaded);
            zmcd04.Commit.Visibility = Visibility.Collapsed;
            zmcd04.uploadArea.Visibility = Visibility.Collapsed;

            CmesWindows _win = new CmesWindows();//构造一个弹出窗口
            _win.ResizeMode = ResizeMode.NoResize;//设置不能修改窗口大小
            _win.Header = zmcd04.eTitle;//设置Title
            _win.Content = zmcd04;
            _win.ShowDialog();//模态显示弹出窗口
        }

        /// <summary>
        /// 当ZMCD04当做明细页面的时候，设置控件不可编辑
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ZMCD04_Loaded(object sender, EventArgs e)
        {
            ZMCD04 zmcd04 = sender as ZMCD04;
            BaseTools.EFDataFieldNotEnabled(zmcd04.GetChildObjects<EFDataField>(null, true));
        }

        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DownLoad_HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            HyperlinkButton link = sender as HyperlinkButton;
            EIRow row = (link.ParentOfType<GridViewRow>().Item as UIBaseEntity).GetEIRow();

            EIInfo info = new EIInfo();
            info.Attributes.Add(EIConstants.ServiceNameKey, "ZMCD06");
            info.Attributes.Add(EIConstants.MethodNameKey, "queryFiles");
            EIBlock block = info.AddBlock(EIConstants.QueryStatusBlock);

            EIColumn column = new EIColumn();
            column.Name = "fdForeignId";
            block.AddColumn(column);

            EIRow row1 = new EIRow();
            row1.Add("fdForeignId", row["fdKeyId"]);
            block.AddRow(row1);

            HttpServiceAgent agent = new HttpServiceAgent();
            agent.CallService(info, OnDoWorkCompleted);
        }

        /// <summary>
        /// 修改按钮中的回调函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnDoWorkCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            ZMCD05 zmcd05 = new ZMCD05();
            zmcd05.EIDataContext = new Platform.Core.UI.EIDataContext();
            zmcd05.EIDataContext.Update(e.EIInfo);

            CmesWindows _win = new CmesWindows();//构造一个弹出窗口
            _win.ResizeMode = ResizeMode.NoResize;//设置不能修改窗口大小
            _win.Header = zmcd05.eTitle;//设置Title
            _win.Content = zmcd05;
            _win.ShowDialog();//模态显示弹出窗口
        }
    }
}
